package com.ccit.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ccit.service.UserService;
import com.ccit.model.User;

import java.net.SocketOption;

/**
 * User的路由接口服务
 * 
 * @author 
 *
 */
@RestController
public class UserController {

	/** UserService服务 */
	@Autowired
	private UserService userService;
	
	/**
	 * 查询所有User数据的方法
	 * @param
	 * @return
	 */
	@GetMapping(value = "/User", produces = {"application/json;charset=UTF-8"})
	public String find(User value) {
		return userService.find(value);
	}
	
	/**
	 * 通过id查询User数据的方法
	 * @param
	 * @return
	 */
	@GetMapping(value = "/User/{id}", produces = {"application/json;charset=UTF-8"})
	public String findOne(@PathVariable(name="id") String id) {
		return userService.findOne(id);
	}
	
	/**
	 * 插入User属性不为空的数据方法
	 * @param
	 * @return
	 */
	@PostMapping(value = "User", produces = {"application/json;charset=UTF-8"})
	public String save(User value) {
        System.out.print(value.getPassword());
		return userService.saveNotNull(value);
	}
	
	/**
	 * 更新User属性不为空的数据方法
	 * @param
	 * @return
	 */
	@PutMapping(value = "/User", produces = {"application/json;charset=UTF-8"})
	public String update(User value) {
		return userService.updateNotNullById(value);
	}
	
	/**
	 * 通过id删除User数据方法
	 * @param
	 * @return
	 */
	@DeleteMapping(value = "/User/{id}", produces = {"application/json;charset=UTF-8"})
	public String delete(@PathVariable(name="id") String id) {
		return userService.deleteById(id);
	}
}
